package com.api.shopapi.service.impl;

import com.api.shopapi.entity.MeshDevice;
import com.api.shopapi.entity.MeshDeviceProperties;
import com.api.shopapi.entity.dto.MeshDeviceDTO;
import com.api.shopapi.mapper.MeshDeviceMapper;
import com.api.shopapi.mapper.MeshDevicePropertiesMapper;
import com.api.shopapi.service.MeshDeviceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("MeshDeviceServiceImplOne")
public class MeshDeviceServiceImpl implements MeshDeviceService {

    @Autowired
    private MeshDeviceMapper meshDeviceMapper;

    @Autowired
    private MeshDevicePropertiesMapper meshDevicePropertiesMapper;

    @Override
    public int insert(MeshDevice meshDevice) {
        return meshDeviceMapper.insert(meshDevice);
    }

    @Override
    public PageInfo<MeshDeviceDTO> getPageByGwId(int pageIndex, int pageSize, String gwId, String model) {
        PageHelper.startPage(pageIndex,pageSize);
        List<MeshDeviceDTO> meshDeviceDTOList = meshDeviceMapper.getPageByGwId(gwId, model);
        for (MeshDeviceDTO meshDeviceDTO : meshDeviceDTOList) {
            List<MeshDeviceProperties> devicePropertiesList = meshDevicePropertiesMapper.getListByDeviceCode(meshDeviceDTO.getDeviceCode());
            meshDeviceDTO.setDevicePropertiesList(devicePropertiesList);
        }
        return new PageInfo<>(meshDeviceDTOList);
    }
}
